from PySide6.QtWidgets import QMenu
from PySide6.QtGui import QKeySequence

class FileMenu(QMenu):
    """文件菜单

    :param QMenu: PySide6 菜单类
    """
    def __init__(self):
        """初始化
        """
        super().__init__()
        self.setup_ui()
    
    def setup_ui(self):
        """设置菜单项
        """
        self.setTitle("文件(&F)")
        new_file = self.addAction("新建(&N)")
        new_window = self.addAction("新窗口(&W)")
        open_file = self.addAction("打开(&O)")
        save_file = self.addAction("保存(&S)")
        self.addSeparator()
        save_file_as = self.addAction("另存为(&A)")
        print_file = self.addAction("打印(&P")
        self.addSeparator()
        exit_ = self.addAction("退出(&X)")

        # 添加快捷方式
        new_file.setShortcut(QKeySequence.StandardKey.New)
        new_window.setShortcut("Ctrl+Shift+N")
        open_file.setShortcut(QKeySequence.StandardKey.Open)
        save_file.setShortcut(QKeySequence.StandardKey.Save)
        save_file_as.setShortcut(QKeySequence.StandardKey.SaveAs)
        print_file.setShortcut(QKeySequence.StandardKey.Print)
        exit_.setShortcut(QKeySequence.StandardKey.Close)
